package com.atguigu.lease.web.admin.controller;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 李壮
 * @CreateTime: 2025-05-06
 * @Version: 1.0
 */

@RestController
@RequestMapping("/admin/facility")
@Tag(name = "配套管理")
public class FacilityController {

    @Autowired
    FacilityService facilityService;


    @Operation(summary = "新增或修改配套信息")
    @PostMapping("saveOrUpdate")
    public Result saveOrUpdate(@RequestBody FacilityInfo facilityInfo){

        facilityService.saveOrUpdate(facilityInfo);
        return Result.ok();
    }

    @Operation(summary = "[根据类型]查询配套信息列表")
    @GetMapping("list")
    public Result list(@RequestParam(value = "itemType",required = false)ItemType itemType){

        LambdaQueryWrapper<FacilityInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(itemType != null,FacilityInfo::getType,itemType);
        List<FacilityInfo> list = facilityService.list(lambdaQueryWrapper);
        return Result.ok(list);

    }

    @Operation(summary = "根据id删除配套信息")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long id){

        facilityService.removeById(id);
        return Result.ok();
    }
}
